﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

namespace SchemaMonitor.json
{

    public class CDebugToken : CDict
    {
        //Members
        public long AppId;
        public string Application;
        public int ExpiresInSecs;
        public bool IsValid;
        public int IssuedAt;
        public long UserId;
        public List<string> Scopes;
        public CDictError Error;
        public DateTime Expires;


        //Constructor
        public CDebugToken(dynamic jsonDict) : this((Dictionary<string, object>)jsonDict) { }
        public CDebugToken(Dictionary<string, object> d) : base(d)
        {
            AppId = AsLong("app_id");
            Application = AsStr("application");
            ExpiresInSecs = AsInt("expires_at");
            IsValid = AsBool("is_valid");
            IssuedAt = AsInt("issued_at");
            UserId = AsLong("user_id");
            Scopes = AsListStr("scopes");
            Error = AsError("error");

            Expires = DateTime.Now.AddSeconds(ExpiresInSecs);
        }

        public bool HasError {  get { return null == Error; } }
    }
}
